import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbjob, tbjobpublish } from '../../../../atoms/db';

const logger = anylogger('pages/api/zllweapp/zuoyepiyue/s003.api');

export type Result = {
	ok: true;
	content: Pick<ITbjob, 's_jobcontext' | 'sjob_id'>[]
} | {
	ok: false;
	message: string;
};

export type Message = {
	id: string;
}

/**
 * pages/api/zllweapp/zuoyepiyue/s003.api
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const { id } = req.body as Message;
		const content = await tbjob().select('s_jobcontext', 'sjob_id').where({
			sjob_id: id
		});
		res.status(200).json({ ok: true, content });
	} catch (error) {
		logger.trace(error);
		res.status(200).json({ ok: false, message: (error as Error).message });
	}
});

export const config = {} as PageConfig;

export default handler;
